{include file="common/_header"}
{include file="common/_header1"}

<body class="layui-anim layui-anim-up">
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">报表管理</a>
            <a>
              <cite>商品报表管理</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">


    <!--    <div class="layui-row">-->
    <!--        <form class="layui-form layui-col-md12 x-so">-->
    <!--            <input type="text" name="shop_name"  placeholder="请输入商铺名称" value="{//$data.get['shop_name']}" autocomplete="off" class="layui-input">-->
    <!--            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>-->
    <!--        </form>-->
    <!--    </div>-->
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <div class="layui-input-inline">
                {if $data.isdisplay == true}
                <div class="layui-unselect layui-form-select spf_id" style="display:inline-block;">
                    <!--                    <select name="spf_id" lay-filter="spf_id" class="select_subplat" onchange="sChange(this);">-->
                    <select name="spf_id" lay-filter="spf_id" class="select_subplat">
                        <option value="">请选择加盟商</option>
                        {volist name="data.subplatlist" id="vo"}
                        <option value={$key} {$data.get.spf_id != '' && $data.get.spf_id == $key?'selected':''}>{$vo}</option>
                        {/volist}
                    </select>
                </div>
                {/if}
                <div class="layui-unselect layui-form-select shop_id" style="display:inline-block;">
                    <select name="shop_id" lay-filter="shop_id" class="select_shop">
                    </select>
                </div>
                <div class="layui-input-inline">
                    <input type="text" name="time" class="layui-input" id="test1" placeholder="请选择时间" readonly value="{$data.get.time}">
                </div>
                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>

        </form>
    </div>

    <table id="tables" class="layui-table">
        <thead>
        <tr>
            <th>ID</th>
            <th>商铺名称</th>
            <th>商品名称</th>
            <th>日期</th>
            <th>天数</th>
            <th>收入金额</th>
            <th>销售数量</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data.data" id="vo"}
        <tr class="table_tr">
            <td>{$vo.id}</td>
            <td>{$vo.shopname}</td>
            <td>{$vo.name}</td>
            <td>开始时间:{$vo.start|date="Y-m-d"}<br>结束时间:{$vo.end|date="Y-m-d"}</td>
            <td>{$vo.days}</td>
            <td>{$vo.amount}</td>
            <td>{$vo.count}</td>

        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page_all">
        {$page|raw}
    </div>
</div>
<script src="/static/admin/lib/layui/layui2.js" charset="utf-8"></script>
<script type="text/javascript">
    layui.use('laydate', function(){
        let laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#test1'
            , range: true
        });

        //国际版
        laydate.render({
            elem: '#test1-1'
            ,lang: 'en'
        });
    });
</script>
<script>
    jQuery(function($){
        var subplatform = "{$data.get.spf_id}";
        var shopid = "{$data.get.shop_id}";
        console.log(subplatform);
        console.log(shopid);
        // $(".select_shop").append("<option value='1'>2</option>");
        selectedProducts(subplatform,shopid)
    });
    function selectedProducts(subplatform,shopid){
        if(subplatform != "" || subplatform == '0') {
            $.ajax({
                type: "get",
                dataType:"json",
                url: "/products/linkage?spf_id=" + subplatform,
                async:"true",
                success: function (result) {
                    console.log(result);
                    if(result.data != ""){
                        console.log(56);
                        $(".select_shop").empty();
                        $(".select_shop").append("<option value=''>请选择商铺</option>");
                        // var count = result.list.length;
                        $.each(result.data,function(i,val){
                            // console.log(34);
                            // console.log(val);
                            // console.log(shopid);
                            if(val.id == shopid){
                                // console.log(12434);
                                $(".select_shop").append("<option value='"+val.id+"' selected>"+val.shopname+"</option>");
                            } else {
                                $(".select_shop").append("<option value='"+val.id+"'>"+val.shopname+"</option>");
                            }
                        });
                        layui.form.render("select");//重新渲染 固定写法
                    } else {
                        console.log(45);
                        $(".select_shop").empty();
                        $(".select_shop").append("<option value=''>请选择商铺</option>");
                        layui.form.render("select");//重新渲染 固定写法
                    }
                },
            });
        }else{
            // console.log(345);
            $(".select_shop").empty();
            $(".select_shop").append("<option value=''>请选择商铺</option>");
            layui.form.render("select");//重新渲染 固定写法
        }

    }
    layui.use("form",function(){
        var form = layui.form;
        form.on('select(spf_id)', function (sub) {
            console.log(sub.value);
            selectedProducts(sub.value,'');
        });
    })
    // $(".select_subplat").change(function(){
    //     console.log(345);
    //     subid = $(this).val();
    //     selectedProducts(subid,'');
    // });
    // function sChange(ele){
    //     ele = $(ele);
    //     console.log(ele.val());
    //
    //
    // }
</script>
<script>

    // 搜索
    // Ajaxpage();
    // function Ajaxpage(curr) {
    //     var key = $('#keydown').val();
    //     var num = $('#num').val();
    //     $.getJSON('{:url("/admin/Repl/please")}', {
    //         page: curr || 1, key:key, key: num
    //     }, function (data) {
    //         console.log(data);
    //     })
    // }

    $(function () {
        // 表格选中行的同时选中单选框
        $("#tables tr:gt(0)").click(function () {
            $(this).find(":radio").prop("checked", true);
        });

    });

    //js放到table下，才能检测到tr数组
    var trs = document.getElementById("tables").getElementsByTagName("tr");
    $(function () {
        for (var i = 0; i < trs.length; i++) {
            trs[i].onmousedown = function () {
                mousedownclick(this);
            }
        }
    });

    function mousedownclick(obj) {
        for (var j = 0; j < trs.length; j++) {
            if (trs[j] == obj) {
                if (trs[0] != obj) {
                    trs[j].style.background = '#D0E9C6';
                    // 启用新增和编辑按钮
                    $("#edits").removeAttr("disabled");//启用按钮
                    $('#edits').removeClass('layui-disabled');
                }
            } else {
                trs[j].style.background = '';
            }
        }
    }
</script>
</body>

{include file="common/_bottom"}